home *** CD-ROM | disk | FTP | other *** search
- /*****
- * menus.c
- *
- *
- *****/
-
- #include <string.h>
-
- #include "mytypes.h"
- #include "ResRefs.h"
- #include "error.h"
-
- #include "globals.h"
- #include "game.h"
- #include "outgoing.h"
- #include "menus.h"
- #include "tcpstuff.h"
- #include "connexions.h"
- #include "window.h"
- #include "main.h"
- #include "util.h"
- #include "preffile.h"
-
- Style gCurrentStyle = kPlainStyle;
- Boolean gHasPopupControl;
-
- /* Templates */
- void enable (MenuHandle menu, short item, short ok);
- void SetUpMenus(void);
- void HandleMenuChoice(long menuChoice);
- void HandleAppleChoice(short item);
- void HandleFileChoice(short item);
- void HandleEditChoice(short item);
- void HandleOptionChoice(short item);
- void HandleWindowChoice(short item);
- void HandleFontChoice(short item);
- void HandleSizeChoice(short item);
- void HandleCommandsChoice(short item);
-
- void SetUpMenus(void)
- {
- Handle menuBar;
- MenuHandle menu;
- ControlHandle control;
- OSErr myErr;
- long feature;
- short nnn;
-
- menuBar = GetNewMBar(rMenuBar); /* read menus into new menu list */
- SetMenuBar(menuBar); /* set to the current menu list */
- DisposHandle(menuBar);
-
- menuBar = GetNewMBar(kBaseResID);
- SetMenuBar(menuBar);
-
- menu = GetMHandle(mApple);
- AddResMenu(menu, 'DRVR');
-
- MenuHandle man = GetMHandle(mOption);
- CheckItem(man, iSound, gPrefs.useSound);
- CheckItem(man, iAutoFlag, gPrefs.autoFlag);
-
- menu = GetMenu(mFont);
- InsertMenu(menu, -1);
- AddResMenu(menu, 'FONT');
-
- // you wanna see ugly? you wanna see?
- // I'll show you ugly.
- man = GetMHandle(mFont);
- Str255 sting, ms;
- GetFontName(gPrefs.currentFont, sting);
- sting[sting[0]] = 0;
- for (nnn=0;nnn<CountMItems(man);nnn++) {
- GetItem(man, nnn, ms);
- ms[ms[0]] = 0;
- if (!strcmp((char *) ms, (char *) sting))
- CheckItem(man, nnn, true);
- }
- // that shit worked first time. unbelieveable.
-
- menu = GetMenu(mSize);
- InsertMenu(menu, -1);
- CheckItem(GetMHandle(mSize), gPrefs.currentSize - 6, true);
-
- DrawMenuBar();
-
- // HandleFontChoice(gLastFont);
- // HandleSizeChoice(3);
-
- myErr = Gestalt(gestaltPopupAttr, &feature);
-
- gHasPopupControl = ((myErr == noErr) && (feature & (1 << gestaltPopupPresent)));
-
- if (gHasPopupControl)
- control = GetNewControl(kBaseResID, FrontWindow());
- }
- /* end SetUpMenus */
-
-
- /****
- * AdjustMenus()
- *
- * Enable or disable the items in the Edit menu if a DA window
- * comes up or goes away. Our application doesn't do anything with
- * the Edit menu.
- *
- ****/
-
- void AdjustMenus(void)
- {
- MenuHandle fileMenu;
-
- fileMenu = GetMHandle(mFile);
- enable(fileMenu, iOpen, nexStatus[0] == kStatClosed);
- enable(fileMenu, iKillConn, nexStatus[0] != kStatClosed);
- enable(fileMenu, iClose, gGames != 0);
- }
-
- static void
- enable(MenuHandle menu, short item, short ok)
- {
- if (ok)
- EnableItem(menu, item);
- else
- DisableItem(menu, item);
- }
-
-
- /*****
- * HandleMenu(mSelect)
- *
- * handles the menu selections and disperses the choices to the correct functions.
- *
- *****/
-
- void HandleMenu(long menuChoice)
- {
- short menu;
- short item;
-
- if(menuChoice !=0)
- {
- menu = HiWord(menuChoice);
- item = LoWord(menuChoice);
-
- switch(menu)
- {
- case mApple:
- HandleAppleChoice(item);
- break;
- case mFile:
- HandleFileChoice(item);
- break;
- case mEdit:
- HandleEditChoice(item);
- break;
- case mOption:
- HandleOptionChoice(item);
- break;
- case mWindow:
- HandleWindowChoice(item);
- break;
- case mFont:
- HandleFontChoice(item);
- break;
- case mSize:
- HandleSizeChoice(item);
- break;
- case mCommands:
- HandleCommandsChoice(item);
- break;
- default:
- break;
- }
- HiliteMenu(0);
- }
- }
-
- void HandleAppleChoice(short item)
- {
- MenuHandle appleMenu;
- Str255 accName;
- short accNumber;
- GrafPtr savePort;
-
- switch(item)
- {
- case iAbout:
- Alert(rAboutAlrt, nil);
- break;
- default:
- GetPort(&savePort);
- appleMenu = GetMHandle(mApple);
- GetItem(appleMenu, item, accName);
- accNumber = OpenDeskAcc(accName);
- SetPort(savePort);
- break;
- }
- }
-
- void HandleFileChoice(short item)
- {
- switch (item) {
- case iOpen:
- if (nexStatus[0] == kStatClosed)
- OpenTalker();
- break;
- case iKillConn:
- if (nexStatus[0] != kStatClosed) {
- ReleaseStreams();
- tprintf("Connection closed.\r");
- }
- break;
- case iClose:
- WindowPtr win = FrontWindow();
- if (win != myWindow)
- CloseGameWindow(win);
- break;
- case iQuit:
- timeToQuit = true;
- break;
- default: break;
- }
- }
-
- void HandleEditChoice(short item)
- {
- switch (item) {
- case iCut:
- TECut(myText);
- ZeroScrap();
- TEToScrap();
- break;
- case iCopy:
- TECopy(myText);
- ZeroScrap();
- TEToScrap();
- break;
- case iPaste:
- TEPaste(typeText);
- break;
- default: break;
- }
- }
-
- void HandleOptionChoice(short item)
- {
- MenuHandle optionMenu;
-
- optionMenu = GetMHandle(mOption);
-
- switch (item) {
- case iFlip:
- DoFlip();
- break;
- case iSound:
- gPrefs.useSound = !gPrefs.useSound;
- CheckItem(optionMenu, iSound, gPrefs.useSound);
- break;
- case iAutoFlag:
- gPrefs.autoFlag = !gPrefs.autoFlag;
- CheckItem(optionMenu, iAutoFlag, gPrefs.autoFlag);
- break;
- case iPrefs:
- PrefDialog();
- break;
- case iPrefs2:
- PrefDialog2();
- break;
- default: break;
- }
- }
-
- static const char *hiddenString =
- "\rHidden Features:\r\
- • While playing or observing a game, hold down the option key to visually see the last move\r\
- • Use the Help and Del keys to scroll the text window up and down one line at a time\r\
- • In bughouse, click on pieces on right to place\r\
- • Use the up and down arrow keys to access a command history\r\
- • Hitting the escape key while dragging a piece will cancel the drag\r\r";
-
- static const char *versionString =
- "\rVersion History:\r\
- • Version 1.3\r\
- Better piece dragging (backgrounds while dragging), sounds for tells, fixed current version checking bug,\
- new hidden feature, gansta egg\r\
- • Version 1.2\r\
- Timeseal built in, automatic current version checking\r\
- • Version 1.13\r\
- Fixed bug which would cause a rare buffer overflow error when using Timestamp\r\
- • Version 1.12\r\
- Fixed Timestamp bug that would add an hour to your clock\r\
- • Version 1.11\r\
- Timestamp built in\r\
- • Version 1.1\r\
- Numerous bug fixes, resizeable windows, command menu, much more\r\
- • Version 1.0\r\
- First release\r\r";
-
- static const char *bugsString =
- "\rAbout Bugs & Suggestions:\r\
- Please check my web page or finger my account to make sure you have the latest version before mailing me \
- bugs and suggestions. When reporting a bug, please don't say something like 'it \
- crashed once.' I need more than that to help you. Another request is to cut it out \
- with the reports of Fixation not working with wild 5 ;-j (Read the online help if \
- this makes no sense.)\r\
- Known bugs:\r\
- • color bleeding in text window\r\
- • smaller than normal windows in bughouse are messed up\r\
- • multiple line tells etc. are not colored correctly in FICS -- I'm waiting for a server change on this one\r\
- • grow boxes redraw incorrectly\r\
- • when moves are taken back, last move is still shown\r\
- • there's a slight sound conflict with Norton Filesaver\r\
- • on a couple people's machines, Fixation won't work unless another TCP app is run first\r\
- If you can provide details, I might eventually be able to fix the bug.\r\
- Here is a list of suggestions I've already had or thought of myself, which obviates \
- the need to report them unless you wish to add detail:\r\
- firewall support, saving games locally, move lists, color options for higlighting, \
- display legal moves, logging server output, using patterns for square colors, \
- auto-close windows option, highlighting draw offer, \
- promote options, flip partner's board properly, time highlighting when clock running down.\r\
- I'm sure I'm forgetting some. Just because I should do these things doesn't mean I \
- will, however. My volunteer time is limited.\r\r";
-
- void HandleWindowChoice(short item)
- {
- Game *game;
- switch (item) {
- case iNormalSize:
- WindowPtr win = FrontWindow();
- if (!win)
- return;
- game = FindGameFromWindow(win);
- if (!game)
- return;
- short delta = 32 * 8 - game->boardRect.right;
- SetGameWindowSize(game, delta);
- break;
- case iTextWind:
- if (FrontWindow() == myWindow)
- SendBehind(myWindow, nil);
- else
- SelectWindow(myWindow);
- break;
- case iGameWindOne:
- game = gGames;
- while (game) {
- if (game->isFirst)
- SelectWindow((WindowPtr) game->wind);
- game = game->next;
- }
- break;
- case iGameWindTwo:
- game = gGames;
- while (game) {
- if (game->isSecond)
- SelectWindow((WindowPtr) game->wind);
- game = game->next;
- }
- break;
- case iHidden:
- tprintf("%s", hiddenString);
- break;
- case iBugsSuggestions:
- tprintf("%s", bugsString);
- break;
- case iVersionHistory:
- tprintf("%s", versionString);
- break;
- default: break;
- }
- }
-
- void HandleCommandsChoice(short item)
- {
- switch (item) {
- case icHelp:
- bprintf("help\n");
- break;
- case icCommandList:
- bprintf("help commands\n");
- break;
- case icWho:
- bprintf("who\n");
- break;
- case icHistory:
- bprintf("history\n");
- break;
- case icFinger:
- bprintf("finger\n");
- break;
- case icVariables:
- bprintf("var\n");
- break;
- case icMessages:
- bprintf("messages\n");
- break;
- case icClearMessages:
- bprintf("clear\n");
- break;
- case icMore:
- bprintf("more\n");
- break;
-
- case icResign:
- bprintf("resign\n");
- break;
- case icDraw:
- bprintf("draw\n");
- break;
- case icAbort:
- bprintf("abort\n");
- break;
- case icFlag:
- bprintf("flag\n");
- break;
- case icMoretime60:
- bprintf("moretime 60\n");
- break;
- default: break;
- }
- }
-
- TextStyle tempStyle = {0, 0, 0, 9, {0, 0, 0}};
-
- void HandleFontChoice(short item)
- {
- short fontNumber, nnn;
- Str255 fontName;
- MenuHandle menuHandle;
-
- menuHandle = GetMHandle(mFont);
-
- for (nnn=0;nnn<CountMItems(menuHandle);nnn++)
- CheckItem(menuHandle, nnn, nnn == item);
-
- GetItem(menuHandle, item, fontName);
- GetFNum(fontName, &fontNumber);
-
- gPrefs.currentFont = fontNumber;
-
- SetPort(myWindow);
- short oldstart = (**myText).selStart, oldend = (**myText).selEnd;
- TESetSelect(0, 32767, myText);
-
- tempStyle.tsFont = gPrefs.currentFont;
- TESetStyle(doFont, &tempStyle, true, myText);
- TECalText(myText);
- CalcVisLines();
- CalcVBar();
-
- TESetSelect(oldstart, oldend, myText);
-
- // TextFont(gCurrentFont);
- // SetUpWindow();
- }
-
- void HandleSizeChoice(short item)
- {
- short fontSize, nnn;
- MenuHandle menuHandle;
-
- menuHandle = GetMHandle(mSize);
-
- for (nnn=0;nnn<CountMItems(menuHandle);nnn++)
- CheckItem(menuHandle, nnn, nnn == item);
-
- fontSize = item + 6; // Start the font size at 7 and go to 16
-
- gPrefs.currentSize = fontSize;
-
- SetPort(myWindow);
- short oldstart = (**myText).selStart, oldend = (**myText).selEnd;
- TESetSelect(0, 32767, myText);
-
- tempStyle.tsSize = gPrefs.currentSize;
- TESetStyle(doSize, &tempStyle, true, myText);
- TECalText(myText);
- CalcVisLines();
- CalcVBar();
-
- TESetSelect(oldstart, oldend, myText);
-
- }